/*
 * statusFrame.java
 *
 * Created on March 7, 2009, 3:46 PM
 */
package forensicsGUI;

import javax.swing.JPanel;
import java.util.Timer;
import java.util.TimerTask;
import java.io.BufferedReader;
import java.io.FileReader;
import java.awt.Dimension;
import java.awt.Rectangle;

/**
 *
 * @author  marc
 */
public class statusFrame extends javax.swing.JFrame {

    /** Creates new form statusFrame */
    private fetchStatistics stats = new fetchStatistics();
    private Timer timer;
    private boolean parallel = true;

    public statusFrame(boolean parallel) {
        initComponents();
        centerScreen();
        try {
            Dimension dim = tabbedPane.getSize();
            dim.setSize(tabbedPane.getSize().getWidth() + 8, tabbedPane.getSize().getHeight() + 8);
            setSize(dim);
            tabbedPane.updateUI();
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.parallel = parallel;
        tabbedPane.setEnabledAt(1, false);
    }

    /**
     * Centers the frame on the screen.
     */
    public void centerScreen() {
        Dimension dim = getToolkit().getScreenSize();
        Rectangle abounds = getBounds();
        setLocation((dim.width - abounds.width) / 2,
                (dim.height - abounds.height) / 2);
        requestFocus();
    }

    /**
     * Shows the audit tab.
     */
    public void showAudit() {
        tabbedPane.setEnabledAt(0, false);
        tabbedPane.setEnabledAt(1, true);
        tabbedPane.setSelectedIndex(1);
        setVisible(true);
    }

    /**
     * Loads audit information for a given instance.
     * @param instance
     */
    public void loadAuditInformation(AuditedInstances instance) {
        String loc = "";
        loc = instance.getOutputDirectory();
        try {

            jTextPane1.read(new BufferedReader(new FileReader(loc + "/audit.txt")), loc + "audit.txt");
        } catch (Exception e) {
        }
        try {

            jTextArea1.read(new BufferedReader(new FileReader(loc + "/investigation.txt")), loc + "investigation.txt");
        } catch (Exception e) {
        }
    }

    public void setFinished() {
        tabbedPane.setEnabledAt(1, true);
        tabbedPane.updateUI();
    }

    
    public JPanel getPanel() {
        return updatePanel;
    }
/** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    public void startUpdateTimer(ErrorInstanceLogger pidGather) {
//        stats.setTextExecutionField(executionTime);
        //      stats.setTextThreadsField(threadsExecuting);
        //    stats.setPid(pidGather);
//        timer = new Timer();
        //      timer.schedule(stats,1000, 10 * 1000); // every 10 seconds
    }

    public void stopUpdateTimer() {
        //timer.cancel();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabbedPane = new javax.swing.JTabbedPane();
        updatePanel = new javax.swing.JPanel();
        auditPane = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        setTitle("Execution Instance");

        updatePanel.setMinimumSize(new java.awt.Dimension(300, 300));
        updatePanel.setLayout(new java.awt.BorderLayout());
        tabbedPane.addTab("Application Output", updatePanel);

        jLabel1.setText("Case Information");

        jLabel3.setText("Audit Results");

        jScrollPane2.setViewportView(jTextPane1);

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout auditPaneLayout = new javax.swing.GroupLayout(auditPane);
        auditPane.setLayout(auditPaneLayout);
        auditPaneLayout.setHorizontalGroup(
            auditPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(auditPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 215, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 322, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, auditPaneLayout.createSequentialGroup()
                .addContainerGap(267, Short.MAX_VALUE)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(281, 281, 281))
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 658, Short.MAX_VALUE)
        );
        auditPaneLayout.setVerticalGroup(
            auditPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(auditPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(auditPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27))
        );

        tabbedPane.addTab("Audit Details", auditPane);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(tabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(tabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    /**
     * @param args the command line arguments
     */
    /* public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new statusFrame().setVisible(true);
    }
    });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel auditPane;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JTabbedPane tabbedPane;
    private javax.swing.JPanel updatePanel;
    // End of variables declaration//GEN-END:variables
}
